//
//  MovieCell.m
//  卢卡的时光网
//
//  Created by 卡神 on 15/7/20.
//  Copyright © 2015年 lok. All rights reserved.
//

#import "MovieCell.h"
#import "StarView.h"
#import "UIImageView+WebCache.h"

@implementation MovieCell


- (void)setModel:(MoiveInformation *)model {
    _model = model;
    self.starView.average = _model.average;
    [self setNeedsLayout];
}

- (void)layoutSubviews {
    [self.contentView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_main"]]];
    
    _titleLabel.text = _model.title;
    _yearLabel.text = [NSString stringWithFormat:@"年份:  %@", _model.year];
    NSString *imageUrl = [_model.images valueForKey:@"medium"];
    [_contentImage sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"1"]];
    _contentImage.contentMode = UIViewContentModeScaleAspectFit;
    _fractionLabel.text = [NSString stringWithFormat:@"%.1lf", _model.average];
    self.starView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_main"]];
//    //获取星星图片
//    UIImage *grayStar = [UIImage imageNamed:@"gray"];
//    UIImage *yellowStar = [UIImage imageNamed:@"yellow"];
//    //设定灰色和黄色星星的视图frame
//    UIView *gray = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_contentImage.frame) + 8, CGRectGetMaxY(_titleLabel.frame) + 12, grayStar.size.width * 5, grayStar.size.height)];
//    UIView *yellow = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_contentImage.frame) + 8, CGRectGetMaxY(_titleLabel.frame) + 12, grayStar.size.width * _model.average * 5 / 10, grayStar.size.height)];
//    //设置
//    [gray setBackgroundColor:[UIColor colorWithPatternImage:grayStar]];
//    [yellow setBackgroundColor:[UIColor colorWithPatternImage:yellowStar]];
//    
//    [self.contentView addSubview:gray];
//    [self.contentView addSubview:yellow];
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
